<template>
  <div>
    <div class="form">
      <el-form ref="form" :model="form" label-width="80px" :rules="rules">
        <el-form-item label="所属项目:" prop="severity" label-width="300">
          <el-select  v-model="form.projectid" placeholder="请选择" >
            <el-option v-for="(item,index) in bugProject" :key="index" :label="item.name" :value="item.id">{{item.name}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="严重性:" prop="severity" label-width="300">
          <el-select  v-model="form.severity" placeholder="请选择" >
            <el-option v-for="(item,index) in AllSeverity" :key="index" :label="item.severityName" :value="item.severity">{{item.severityName}}</el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="BUG标题:" prop="title" label-width="300">
          <el-input v-model="form.title"></el-input>
        </el-form-item>
        <el-form-item label="报告人:" prop="reportuser" label-width="300">
          <el-input v-model="form.reportuser"></el-input>
        </el-form-item>
      </el-form>
    </div>
    <el-button type="primary" plain @click="addBug('form')">提交</el-button>
    <el-button type="success" plain @click="toAllBug">返回</el-button>
  </div>
</template>

<script>
import { ElMessage } from 'element-plus'
export default {
  name: "addBug",
  data(){
    return{
      form:{},
      bugProject:[],
      AllSeverity:[
        {"severity":10,"severityName":"文字错误"},
        {"severity":20,"severityName":"次要错误"},
        {"severity":30,"severityName":"严重错误"},
      ],
      rules:{
        projectid:[{ required: true, message: '不能为空', trigger: 'blur' }],
        severity:[{ required: true, message: '不能为空', trigger: 'blur' }],
        title:[{ required: true, message: '不能为空', trigger: 'blur' }],
        reportuser:[{ required: true, message: '不能为空', trigger: 'blur' }],
      }
    }
  },methods:{
    getAllBugProject(){
      this.$http.post("/api/api/getAllBugProject").then(res=>{
        this.bugProject=res.data;
      })
    },
    addBug(formName){
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$http.get("/api/api/addBugDetail",{params:this.form}).then(res=>{
            ElMessage('添加成功')
          })
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
    toAllBug(){
      this.$router.replace("/")
    }
  },created() {
    this.getAllBugProject();
  }
}
</script>

<style scoped>
.form{
  margin: 0 auto;
  padding: 0;
  height: 250px;
  width: 300px;
}
</style>